package foxnarabbit;

import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;

public class Playable{

    private int dx;
    private int dy;
    private int x;
    private int y;
    private Image image;
    
    public Playable(String fname){
        ImageIcon ii = new ImageIcon(fname);
        image = ii.getImage();
        x = 20;
        y = 250;
    }
    
    public void move(){
        x = x + dx;
        y = y + dy;
    }

    public int getX(){
        return x;
    }

    public int getY(){
        return y;
    }

    public Image getImage() {
        return image;
    }

    public void keyPressed(KeyEvent e){
        int key = e.getKeyCode();

         if (key == KeyEvent.VK_LEFT) {
            dx = -60;
            if(x <= 20)
                dx = 0;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 60;
            if(x >= 560)
                dx = 0;
        }

        if (key == KeyEvent.VK_UP) {
            dy = -32;
            if(y <= 26)
                dy = 0;
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 32;
            if(y >= 314)
                dy = 0;
        }

   }

     public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;
        }

        if (key == KeyEvent.VK_UP) {
            dy = 0;
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 0;
        }
    }

}

